package com.wq.user.controller;

import com.wq.common.entity.Result;
import com.wq.common.entity.StatusCode;
import com.wq.user.entity.User;
import com.wq.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
@GetMapping("{id}")
    public Result findById(@PathVariable String id){
        User user = userService.findById(id);
        return new Result(true, StatusCode.OK,"查询id成功",user);
    }
    @GetMapping
    public Result findAll(){
        List<User> all = userService.findAll();
        return new Result(true, StatusCode.OK,"查询全部成功",all);
    }
    @PostMapping("sendsms/{phone}")
    public Result sendSms(@PathVariable String phone){
        userService.sendSms(phone);
        return new Result(true, StatusCode.OK,"发送成功");
    }
    @PostMapping("sms/{code}")
    public Result result(@RequestBody User user,@PathVariable String code){
        userService.regist(user,code);
        return new Result(true, StatusCode.OK,"注册成功");
    }
}
